import User from "../entities/User";
import Operator from "./Operator";
import {RC} from "../config/RC";


class CheckUserExistOperator extends Operator{
    public async execute(): Promise<RC> {
        const user_name: string = this.args.getProperty('userName');
        if (user_name === '' || user_name === null || user_name === undefined) {
            return RC.INVALID_ARGUMENT;
        }
        try {
            const isExist = await User.CheckUserExist(user_name);
            if (isExist) {
                return RC.USERNAME_EXIST;
            } else {
                this.args.setProperty('userName_is_exist', isExist);
                return RC.SUCCESS;
            }
        } catch (error) {
            // 处理异常情况
            console.error('Error checking user existence:', error);
            return RC.INTERNAL_ERROR;
        }
    }
}

export default CheckUserExistOperator;